#ifndef FREEWAYMGR_CPP_INCLUDED
#define FREEWAYMGR_CPP_INCLUDED
#include "FreeWayMgr.h"
#include "FreeWayReceiver.h"
#include "FreeWaySender.h"
#include "FreeWayEntry.h"
#include "FreeWayArg.h"
#include "FreeWaySerSender.h"
#include "FreeWayCliSender.h"

FreeWayMgr::FreeWayMgr()
{

}

FreeWayMgr::~FreeWayMgr()
{
    delete fwReceiverPtr;
    fwReceiverPtr = 0;
    delete fwSenderPtr;
    fwSenderPtr = 0;
    delete entry;
    entry = 0;

}


bool FreeWayMgr::start()
{
     LOG(INFO) <<"ac1 " ;

    fwReceiverPtr->activate();


     LOG(INFO) <<"ac2 " ;
    fwSenderPtr->activate();

}

bool FreeWayMgr::init(void * p, int type)
{

    FreeWayArg::getInstance().init();
    m_freewayId =  FreeWayArg::getInstance().getValue("freewayid");
    m_freewayResp = FreeWayArg::getInstance().getValue("freewayresp");
    m_freeWayAccess = FreeWayArg::getInstance().getValue("freewayaccess");
    m_freeWayServerIP = FreeWayArg::getInstance().getValue("freewaysip");

    entry = new FreeWayEntry;
    fwReceiverPtr = new FreeWayReceiver(this);

    if(type == SERVER)
        fwSenderPtr = new FreeWaySerSender(this);
    else if(type == CLIENT)
        fwSenderPtr = new FreeWayCliSender(this);

    entry->init(type);
    fwReceiverPtr->setEntry(entry);
    fwSenderPtr->setEntry(entry);
    fwReceiverPtr->setbrain(p);
    fwSenderPtr->setbrain(p);
    brainp = p;




    LOG(INFO) <<"freewayid: " << m_freewayId;
    LOG(INFO) <<"freewayresp: " << m_freewayResp;
    LOG(INFO) <<"FREEWAYACCESS: " << m_freeWayAccess;
    LOG(INFO) <<"FREEWAYSERVER: " << m_freeWayServerIP;

}


bool FreeWayMgr::send2Client(const char * buf, int len, std::string client)
{
    if(client == "")
    {
        LOG(INFO) << "BroadCast message";
        fwSenderPtr->pushdata(buf, len);
    }



}



std::string FreeWayMgr::m_freewayId = "id";
std::string FreeWayMgr::m_freewayResp = "resp";
std::string FreeWayMgr::m_freeWayAccess = "access";
std::string FreeWayMgr::m_freeWayServerIP = "127.0.0.1";
#endif // FREEWAYMGR_CPP_INCLUDED
